package cn.kgc.shiro;

import cn.hutool.core.util.RandomUtil;
import org.apache.shiro.crypto.hash.SimpleHash;

/**
 * @author 课工场
 * @date 2024/8/21
 * @description shiro中的密码加密操作
 */
public class TestMD5 {

    public static void main(String[] args) {

        test4();

    }


    public static void test1() {

        String password = "123456";
        String hex = new SimpleHash("MD5", password).toHex();
        // e10adc3949ba59abbe56e057f20f883e
        System.out.println("hex = " + hex);

    }

    //  固定盐
    public static void test2() {

        String password = "123456";
        String salt = "java2425";
        String hex = new SimpleHash("MD5", password, salt).toHex();

        // 3ab11414c6d92b781134f56142ca4b69
        System.out.println("hex = " + hex);

    }

    // 随机盐  salt  存储到数据库
    public static void test3() {

        String password = "123456";
        String salt = RandomUtil.randomString(8);
        System.out.println("salt = " + salt);
        String hex = new SimpleHash("MD5", password, salt).toHex();
        System.out.println("hex = " + hex);

    }

    // 随机盐+hash次数
    public static void test4() {

        String password = "123456";
        String salt = "java2425";
        System.out.println("salt = " + salt);
        String hex = new SimpleHash("MD5", password, salt,10).toHex();
        System.out.println("hex = " + hex);// 47f3bebaa5baf1b61124697c5f1a786a

    }


}
